PBDS Hash
์ ๊ดํ ๊ฐ๋จํ ์ ๋ฆฌ.
PBDS๋ Policy based data structures์ ์ฝ์๋ก, g++
์์ ext/pb_ds
์๋์ ์์นํ๋ ๋ฐ์ดํฐ ๊ตฌ์กฐ๋ฅผ ์นญํ๋ค. ์ ์ฝ๋ํฌ์ค ๋ธ๋ก๊ทธ ๊ธ์ ์ฐธ์กฐํ๋ฉด, ์ผ๋ฐ์ ์ธ unordered_map
๋ณด๋ค ํจ์ฌ ๋น ๋ฅธ ์๋๋ก ๋์ํ๋ค๊ณ ํ๋ค.
PBDS์์ ์ฌ์ฉ๊ฐ๋ฅํ ๊ฒ์ gp_hash_table
๊ณผ cc_hash_table
์ธ๋ฐ, gp_hash_table
์ Open Addressing
๋ฐฉ์์ด๊ณ , cc_hash_table
์ Chaining
๋ฐฉ์์ด๋ค. ์ผ๋ฐ์ ์ผ๋ก ์๋๋ฅผ ๋ํ๊ธฐ ์ํด์ PBDS๋ฅผ ๊ฐ์ง๊ณ ์ค๋ ๊ฒ์ด๋ฏ๋ก ์ฑ๋ฅ ํฅ์์ ๋ชฉ์ ์ผ๋ก๋ gp_hash_table
์ ์ฌ์ฉํ๋ ๊ฒ์ด ๋ง๊ฒ ๋ค.
ํค๋๋ฅผ ๋ฃ๊ณ , ์ผ๋ฐ unordered_map
์ฒ๋ผ ์ฌ์ฉํ๋ฉด ๋๋ค. ๋. atcoder
์ ์ํ๋ก ์ ์ถํ ์๋ฃจ์
์ ์๋์ ๊ฐ๋ค.
#include <ext/pb_ds/assoc_container.hpp>using namespace __gnu_pbds;const int HW_RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();struct chash {int operator()(int x) const { return x ^ HW_RANDOM; }};gp_hash_table<int, int, chash> Table;
์ฌ๊ธฐ์ chash
๋ ํด์ ์ ๊ฒฉ ๋ฐฉ์ง์ฉ์ด๋ค. ๊ฐ๋จํ๊ฒ ์ ๊ฒฉ ์๊ฐํ์ง ์๊ณ ๊ทธ๋ฅ ์ธ๊ฑฐ๋ฉด ์๋์ฒ๋ผ๋ ๊ฐ๋ฅํ๋ค.
#include <ext/pb_ds/assoc_container.hpp>using namespace __gnu_pbds;gp_hash_table<int, int> Table;
์ฌ์ฉ์ STL๊ณผ ๊ฑฐ์ ๊ฐ์ผ๋ฏ๋ก, ํธํ๊ฒ ์ฌ์ฉํ ์ ์๋ค.